home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls036.1.Z / tls036.1 / usr / lib / scosmt / sample11 / pe / sample11.rmv / sample11.rmv
Encoding:
Text File  |  1992-09-15  |  6.7 KB  |  330 lines

  1. :
  2. #
  3. #       Copyright (C) 1989 The Santa Cruz Operation Inc. All Rights Reserved
  4. #       This Module contains Proprietary Information of
  5. #       The Santa Cruz Operation Inc, and should be treated as Confidential.
  6. #
  7.  
  8. #BEGIN_CM_SCRIPTLIB
  9. #
  10. # Standard CM script function library
  11. # baselib v1.2
  12. #
  13.  
  14. PATH=/bin:/usr/bin:/etc:.
  15. LANG=english_us.ascii    # Used when scripts are internationalized.
  16. export PATH LANG
  17.  
  18. TMPFILE=/tmp/tmp$$    # Define a temporary file for use if necessary.
  19. TMPFILE1=/tmp/tmp1$$    # Define a temporary file for use if necessary.
  20. TMPFILE2=/tmp/tmp2$$    # Define a temporary file for use if necessary.
  21.  
  22. # Define return values.
  23. : ${OK=0} ${FAIL=1} ${STOP=10}
  24.  
  25. #
  26. # Print an error message.
  27. #
  28. error() {
  29.     echo "\nError: $*" >&2
  30.     return 0
  31. }
  32.  
  33. #
  34. #query the user for a responce.
  35. #a simpler system than prompt, use prompt for
  36. #more sophisticated uses.
  37. #q or Q returns fail, anything else return ok.
  38. #ARGS: <string>, string to print when asking for a responce
  39. #$OK means expression has been resolved or answer is given 
  40. #$FAIL means quit has been selected
  41. #
  42. respond() {
  43.     while    echo "\n${*}\nRespond or enter q to quit: \c" 
  44.     do    read answer
  45.         case $answer in
  46.         Q|q)    return $FAIL                    ;;
  47.         "")    # on a return key return $OK
  48.             answer="RETURNKEY"
  49.             return $OK            ;;
  50.         *)    # on anything else return $OK
  51.             return $OK                    ;;
  52.         esac
  53.     done
  54.     return $OK
  55. }
  56.  
  57. #
  58. # SHOULD BE USED WITH EVERY INSTALLATION SCRIPT
  59. #
  60. # Set the variable $prdperm to  /etc/perms/$PRDVALUE or ./tmp/perms/$PRDVALUE
  61. # If the permlist is found, the values for set, prd, ver, typ, rel,
  62. # and upd are set from the permlist.
  63. # Also determine the OS type, xenix or unix, and set systype accordingly.
  64. #
  65. # sets following information in exported variables
  66. # OSREL: x.x.xy    OSTYPE: unix|xenix    OSBUS: isa|mc|ambi
  67. # OSPRD: <prd value>    OSMCH: <os machine type>
  68. # echo "OS Release: $OSREL    OS Type: $OSTYPE    OS Bus: $OSBUS"
  69. # echo "OS PRD Value: $OSPRD    OS Machine Type: $OSMCH"
  70. #
  71. SETVARS1="Permlist not found"
  72. SETVARS2="Failed to set values from"
  73. SETVARS3="Incorrect prd value in"
  74.  
  75. # Variables set by setvars.
  76. prdperm=
  77. fixperm=fixperm
  78. brand=brand
  79. set=
  80. prd=
  81. typ=
  82. rel=
  83. ser=
  84. upd=
  85. systype=unknown
  86.  
  87. setvars() {
  88.  
  89. # Locate fixperm, brand, and the permlist.
  90.     for _i in /etc ./tmp
  91.     do
  92.         [ -f "$_i/fixperm" ] && fixperm=$_i/fixperm
  93.         [ -f "$_i/brand" ] && brand=$_i/brand
  94.         [ -f "$_i/perms/$PRDVALUE" ] && prdperm=$_i/perms/$PRDVALUE
  95.     done
  96.  
  97.     [ "$prdperm" ] || {
  98.         echo "Warning: $PRDVALUE $SETVARS1" >&2
  99.         return 1
  100.     }
  101.  
  102. # Get the operating system type:
  103.     case `uname -r` in
  104.         2.*)    systype=xenix
  105.             ;;
  106.         3.*)    systype=unix
  107.             ;;
  108.         *)    systype=unknown
  109.             ;;
  110.     esac
  111.  
  112. #
  113. # OS variables setting
  114. # OSREL: x.x.xy        OSTYPE: unix|xenix    OSBUS: isa|mc|ambi
  115. # OSPRD: <prdvalue>    OSMCH: os mch type
  116. #
  117.     OSTYPE=$systype
  118.     case "$OSTYPE" in
  119.         unix)
  120.         eval `sed -n '/^#prd=/s/#//p
  121.             /^#typ=/s/#//p
  122.             /^#rel=/s/#//p' /etc/perms/rtsmd` > /dev/null 2>&1
  123.         OSREL=$rel
  124.         OSPRD=$prd
  125.         OSMCH=$typ
  126.         # Systems 3.2.3 and later are ambi-architectural,
  127.         # ie. will work on either mc or isa.
  128.         case "$OSREL" in
  129.             3.2.[012]*)
  130.             if [ -r /dev/mcapos ]
  131.             then
  132.                 if grep mcapos /etc/perms/rtsmd > /dev/null 2>&1
  133.                 then
  134.                 OSBUS=mc
  135.                 else
  136.                 OSBUS=unknown
  137.                 fi
  138.             else
  139.                 OSBUS=isa
  140.             fi
  141.             ;;
  142.             3.2.[3-9]*)
  143.             OSBUS=ambi
  144.             ;;
  145.             *)
  146.             OSBUS=unknown
  147.             ;;
  148.         esac
  149.         ;;
  150.         xenix)
  151.         eval `sed -n '/^#prd=/s/#//p
  152.             /^#typ=/s/#//p
  153.             /^#rel=/s/#//p' /etc/perms/inst` > /dev/null 2>&1
  154.         OSREL=$rel
  155.         OSPRD=$prd
  156.         OSMCH=$typ
  157.         var=`expr $OSMCH : '.*\(..\)$'`
  158.         if [ "$var" = "MC" -o "$var" = "PS" ]
  159.         then
  160.             OSBUS=mc
  161.         else
  162.             OSBUS=isa
  163.         fi
  164.         ;;
  165.         *)
  166.         OSREL=unknown
  167.         OSTYPE=unknown
  168.         OSBUS=unknown
  169.         OSPRD=unknown
  170.         OSMCH=unknown
  171.         ;;
  172.     esac
  173.  
  174.     export OSREL OSTYPE OSBUS OSPRD OSMCH
  175.     # Clear these vars before they are used below.
  176.     prd=
  177.     rel=
  178.     typ=
  179.     
  180. # Extract product info from the permlist.
  181.     eval `sed -n '/^#set=/s/#//p
  182.         /^#prd=/s/#//p
  183.         /^#typ=/s/#//p
  184.         /^#rel=/s/#//p
  185.         /^#ser=/s/#//p
  186.         /^#upd=/s/#//p' $prdperm` || echo "\n$SETVARS2 $prdperm" >&2
  187.  
  188. # Check the prd value read from the permlist for correctness.
  189.  
  190.     case "$prd" in
  191.         "$PRDVALUE")    return 0
  192.                 ;;
  193.               *)    echo "\n$SETVARS3 $prdperm"  >&2
  194.                 return 1
  195.                 ;;
  196.     esac
  197.  
  198.     return 0
  199. }
  200.  
  201. #
  202. # Standard CM script function library
  203. # configlib V1.0
  204. # Contains: baselib, specificlib
  205. #
  206.  
  207. #
  208. # Standard CM script function library
  209. # specificlib v1.4
  210. # contains: baselib
  211. #
  212.  
  213. #
  214. # restorefiles
  215. # restores root backs that have been made during product installation
  216. # ARG1:    PRDVALUE to use to get standard backup location
  217. # Usage:    restorefiles <prdvalue>
  218. #
  219. RESTORE1_1="
  220. Files that were overwritten during installation have
  221. been backed up in: \c"
  222. RESTORE1_2="
  223. Restoring these files to their original location 
  224. will bring your system back to its prior state, 
  225. if no other products have overwritten these files.
  226. "
  227.  
  228. RESTORE2_1="Chose an option for product \c"
  229. RESTORE2_2="
  230. 1) Restore Backup Files
  231. 2) List Backup Files
  232. a) Abort this product removal.
  233. q) Finished with option select
  234. "
  235. RESTORE3="Enter your selection: " 
  236. RESTORE4="Error: Unable to restore files"
  237. RESTORE5="<Press Return to Continue>"
  238. RESTORE6="
  239. You must hit <DEL> immediately 
  240. to abort this custom removal attempt. 
  241. Continue to hit <DEL> until you 
  242. are out of custom. 
  243. "
  244. RESTORE7="is not a valid response"
  245.  
  246. restorefiles() {
  247. PRDARG=$1
  248.     if [ -s "/usr/lib/custom/${PRDARG}/backup" ]
  249.     then
  250.         echo "$RESTORE1_1"
  251.         echo "/usr/lib/custom/${PRDARG}/backup"
  252.         echo "$RESTORE1_2"
  253.         while :
  254.         do
  255.             echo " "
  256.             echo "$RESTORE2_1"
  257.             echo $PRDARG
  258.             echo "$RESTORE2_2"
  259.             respond "$RESTORE3"
  260.             case $answer in
  261.             1)
  262.                 cd /usr/lib/custom/${PRDARG}/backup    
  263.             # First, copy across only those target directories 
  264.             # that do not exist. (This is to avoid nuking the 
  265.             # mode/uid/gid on dirs that already exist.)
  266.                 find . -type d -print | (
  267.                    cd /
  268.                    while read dnm ; do
  269.                        [ -d $dnm ] || echo $dnm
  270.                    done
  271.                 ) | cpio -pdmu  /  >/dev/null  2>&1
  272.  
  273.             # Next, copy across the files.
  274.                 find . -type f -print | cpio -pdmuv / || {
  275.                     echo "$RESTORE4"
  276.                 }
  277.                 cd /
  278.                 ;;
  279.             2)
  280.                 cd /usr/lib/custom/${PRDARG}/backup    
  281.                 find . -type f -print | pg -p "$RESTORE5"
  282.                 cd /
  283.                 ;;
  284.             a)
  285.                 echo "$RESTORE6"
  286.                 return 1
  287.                 ;;
  288.             q)
  289.                 cd /usr/lib/custom/${PRDARG}
  290.                 rm -rf backup
  291.                 cd /
  292.                 return 0
  293.                 ;;
  294.             *)
  295.                 error "$anwser $RESTORE7"
  296.                 ;;
  297.             esac
  298.         done
  299.     fi
  300.     [ -r /usr/lib/custom/${PRDARG}/backup ] && {
  301.         rm -rf /usr/lib/custom/${PRDARG}/backup
  302.     }
  303.     return 0
  304. }
  305.  
  306. #END_CM_SCRIPTLIB
  307.  
  308. # MAIN    
  309.  
  310. # prd value
  311. PRDVALUE=sample11 ; export PRDVALUE
  312.  
  313. # assumes to be running at the
  314. # root directory.
  315. cd /
  316.  
  317. setvars
  318.  
  319. # optional restoration of files that are in <prd>/backup
  320. echo "Checking for files to be restored..."
  321. restorefiles $PRDVALUE || {
  322.     echo "Warning restore action on backup"
  323.     echo "files has failed."
  324.     exit $FAIL
  325. }
  326.  
  327. rm -rf /usr/lib/custom/${PRDVALUE}
  328.  
  329. exit $OK
  330.